/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Entities;

import java.io.Serializable;
import java.util.List;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

/**
 *
 * @author roycalderon
 */
@Entity
@Table(name = "Book")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "Book.findAll", query = "SELECT b FROM Book b"),
    @NamedQuery(name = "Book.findByIdBook", query = "SELECT b FROM Book b WHERE b.bookPK.idBook = :idBook"),
    @NamedQuery(name = "Book.findByName", query = "SELECT b FROM Book b WHERE b.name = :name"),
    @NamedQuery(name = "Book.findByYear", query = "SELECT b FROM Book b WHERE b.year = :year"),
    @NamedQuery(name = "Book.findByAuthor", query = "SELECT b FROM Book b WHERE b.author = :author"),
    @NamedQuery(name = "Book.findByLocation", query = "SELECT b FROM Book b WHERE b.location = :location"),
    @NamedQuery(name = "Book.findByavaiableCopies", query = "SELECT b FROM Book b WHERE b.avaiableCopies = :avaiableCopies"),
    @NamedQuery(name = "Book.findByAvailability", query = "SELECT b FROM Book b WHERE b.avaiableCopies > 0"),
    @NamedQuery(name = "Book.findByBookTypeidbookType", query = "SELECT b FROM Book b WHERE b.bookPK.bookTypeidbookType = :bookTypeidbookType"),
    @NamedQuery(name = "Book.findByEditorialidEditorial", query = "SELECT b FROM Book b WHERE b.bookPK.editorialidEditorial = :editorialidEditorial"),
    @NamedQuery(name = "Book.findByKnowledgeAreaidknowledgeArea", query = "SELECT b FROM Book b WHERE b.bookPK.knowledgeAreaidknowledgeArea = :knowledgeAreaidknowledgeArea")})
public class Book implements Serializable {
    private static final long serialVersionUID = 1L;
    @EmbeddedId
    protected BookPK bookPK;
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 45)
    @Column(name = "name")
    private String name;
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 45)
    @Column(name = "year")
    private String year;
    @Size(max = 45)
    @Column(name = "author")
    private String author;
    @Size(max = 45)
    @Column(name = "location")
    private String location;
    @Column(name = "avaiableCopies")
    private Integer avaiableCopies;
    @JoinColumn(name = "knowledgeArea_idknowledgeArea", referencedColumnName = "idknowledgeArea", insertable = false, updatable = false)
    @ManyToOne(optional = false, fetch = FetchType.LAZY)
    private KnowledgeArea knowledgeArea;
    @JoinColumn(name = "Editorial_idEditorial", referencedColumnName = "idEditorial", insertable = false, updatable = false)
    @ManyToOne(optional = false, fetch = FetchType.LAZY)
    private Editorial editorial;
    @JoinColumn(name = "bookType_idbookType", referencedColumnName = "idbookType", insertable = false, updatable = false)
    @ManyToOne(optional = false, fetch = FetchType.LAZY)
    private BookType bookType;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "book", fetch = FetchType.LAZY)
    private List<BookList> bookListList;

    public Book() {
    }

    public Book(BookPK bookPK) {
        this.bookPK = bookPK;
    }

    public Book(BookPK bookPK, String name, String year) {
        this.bookPK = bookPK;
        this.name = name;
        this.year = year;
    }

    public Book(int idBook, int bookTypeidbookType, int editorialidEditorial, int knowledgeAreaidknowledgeArea) {
        this.bookPK = new BookPK(idBook, bookTypeidbookType, editorialidEditorial, knowledgeAreaidknowledgeArea);
    }

    public BookPK getBookPK() {
        return bookPK;
    }

    public void setBookPK(BookPK bookPK) {
        this.bookPK = bookPK;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getYear() {
        return year;
    }

    public void setYear(String year) {
        this.year = year;
    }

    public String getAuthor() {
        return author;
    }

    public void setAuthor(String author) {
        this.author = author;
    }

    public String getLocation() {
        return location;
    }

    public void setLocation(String location) {
        this.location = location;
    }

    public Integer getAvaiableCopies() {
        return avaiableCopies;
    }

    public void setAvaiableCopies(Integer avaiableCopies) {
        this.avaiableCopies = avaiableCopies;
    }
    
    

    public KnowledgeArea getKnowledgeArea() {
        return knowledgeArea;
    }

    public void setKnowledgeArea(KnowledgeArea knowledgeArea) {
        this.knowledgeArea = knowledgeArea;
    }

    public Editorial getEditorial() {
        return editorial;
    }

    public void setEditorial(Editorial editorial) {
        this.editorial = editorial;
    }

    public BookType getBookType() {
        return bookType;
    }

    public void setBookType(BookType bookType) {
        this.bookType = bookType;
    }

    @XmlTransient
    public List<BookList> getBookListList() {
        return bookListList;
    }

    public void setBookListList(List<BookList> bookListList) {
        this.bookListList = bookListList;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (bookPK != null ? bookPK.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Book)) {
            return false;
        }
        Book other = (Book) object;
        if ((this.bookPK == null && other.bookPK != null) || (this.bookPK != null && !this.bookPK.equals(other.bookPK))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "Entities.Book[ bookPK=" + bookPK + " ]";
    }
    
}
